<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Eksternal_interface extends CI_Controller {

    public function request_waiting_transaksi($maksimum_data_per_request) {
        $this->load->model("eksternal_interface_model");
        echo $this->eksternal_interface_model->request_waiting_transaksi($maksimum_data_per_request);
    }

    public function request_new_member($maksimum_data_per_request) {
        $this->load->model("eksternal_interface_model");
        echo $this->eksternal_interface_model->request_new_member($maksimum_data_per_request);
    }

    public function request_outbox($maksimum_data_per_request) {
        $this->load->model("eksternal_interface_model");
        echo $this->eksternal_interface_model->request_outbox($maksimum_data_per_request);
    }

    public function request_deposit($maksimum_data_per_request) {
        $this->load->model("eksternal_interface_model");
        echo $this->eksternal_interface_model->request_deposit($maksimum_data_per_request);
    }

    public function flag_queue_message_outbox() {
        $this->load->model("eksternal_interface_model");
        $data = $this->input->post("data");
        $arr_data = json_decode($data);
        $id_queue = array();
        $empty_value = true;
        foreach ($arr_data as $part_data) {
            $this->eksternal_interface_model->flag_queue_message_outbox($part_data->id_queue, $part_data->id_request, $part_data->receiver, $part_data->status);
            $id_queue[] = $part_data->id_queue;
            $empty_value = false;
        }
        if ($empty_value)
            echo "none";
        else
            echo json_encode($id_queue);
    }

    public function sync_local_to_web() {
        $this->load->model("eksternal_interface_model");
        $data = $this->input->post("data");
        $arr_data = json_decode($data);
        $id_queue = array();
        $empty_value = true;
        foreach ($arr_data as $part_data) {
            $this->eksternal_interface_model->sync_local_to_web($part_data);
            $id_queue[] = $part_data->id_log;
            $empty_value = false;
        }
        if ($empty_value)
            echo "none";
        else
            echo json_encode($id_queue);
    }

    public function get_file_sms($filename) {
        $filename = strip_tags($filename);
        echo file_get_contents("./file_upload/" . $filename);
    }

    public function update_status_new_member() {
        $this->load->model("eksternal_interface_model");
        $data = $this->input->post("data");
        $arr_data = json_decode($data);
        foreach ($arr_data as $part_data) {
            $this->eksternal_interface_model->update_status_new_member($part_data->id_member);
        }
        echo "UPDATE SUKSES";
    }

    public function update_status_transaksi() {
        $this->load->model("eksternal_interface_model");
        $data = $this->input->post("data");
        $arr_data = json_decode($data);
        foreach ($arr_data as $part_data) {
            $this->eksternal_interface_model->update_status_request($part_data->id_request, $part_data->status, $part_data->keterangan);
        }
        echo "UPDATE SUKSES";
    }

    public function update_status_outbox() {
        $this->load->model("eksternal_interface_model");
        $data = $this->input->post("data");
        $arr_data = json_decode($data);
        foreach ($arr_data as $part_data) {
            $this->eksternal_interface_model->update_status_outbox($part_data->id_message, $part_data->status);
        }
        echo "UPDATE SUKSES";
    }

    public function update_status_deposit() {
        $this->load->model("eksternal_interface_model");
        $data = $this->input->post("data");
        $arr_data = json_decode($data);
        foreach ($arr_data as $part_data) {
            $this->eksternal_interface_model->update_status_deposit($part_data->id_deposit, $part_data->status);
        }
        echo "UPDATE SUKSES";
    }

    public function m7h_interfaces() {
        $this->load->library("Cipher");
        $this->load->model("pesan_model");
        $data_encrypted = file_get_contents("php://input");
        
/*        $cipher = new Cipher();
        $tgl = date('d', strtotime('today'));
        $bln = date('m', strtotime('today'));
        $thn = date('Y', strtotime('today'));
        $key = ($thn - $tgl * $bln) . "5p1r15@M7#!";die($data_encrypted);
        $decrypted = $cipher->decrypt($data_encrypted, $key);*/
        
        $temp = $data_encrypted[17];
        $data_encrypted[17] = $data_encrypted[7];
        $data_encrypted[7] = $temp;
        $decrypted = base64_decode($data_encrypted);
        
        $arr_data = explode("|", $decrypted);        
        $query = "insert into message_outbox (receiver,content,date_created,id_member,is_sent) values (?,?,now(),?,0)";
        $this->pesan_model->insert_outbox($arr_data[0], $arr_data[1], 11, "RAJAWALI");
        
        echo "Pesan berhasil dikirimkan";
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */